
(function () {
    let url = location.href
    // console.log(url);
    let urlObj = getQueryString(url)
    console.log(urlObj);
    fetch('http://chst.vip:1234/api/getcategorybyid?categoryid=' + urlObj.categoryid)
        .then(reason => {
            return reason.json()
        }).then(res => {
            let data = res.result[0]
            // console.log(data);
            // 获取导航分类
            $('#subNav a').eq(1).html(data.category + '>').attr('href', 'bijia.html?categoryid=' + urlObj.categoryid)
        });

    // 渲染商品详情
    fetch('http://chst.vip:1234/api/getproduct?productid=' + urlObj.productid)
        .then(reason => {
            return reason.json()
        }).then(res => {
            let data = res.result[0]
            console.log(data);
            $('#subNav a').eq(2).html(data.productName)

            let ele = `
            <div class="info">
                <div class="img">
                    ${data.productImg}
                </div>
                <div class="title">${data.productName}</div>
                <div class="count">
                    <div class="row">
                        <div class="coll">
                            <span>当前最低</span>
                            <span>￥6000</span>
                        </div>
                        <div class="coll">
                            <span>优选评论</span>
                            <span>831143条</span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="makeprice">
                ${data.bjShop}
            </div>
            <div class="comment">
                <h4>网友评价</h4>
                <div class="contents">
                    
                </div>
            </div>
            `
            $('main').html(ele);
        });

    // 渲染评论
    setTimeout(() => {
        fetch('http://chst.vip:1234/api/getproductcom?productid=' + urlObj.productid)
            .then(reason => {
                return reason.json()
            }).then(res => {
                let data = res.result
                console.log(data);
                let ele = ''
                data.forEach(item => {
                    ele += `
                     <div class="content">
                        <div class="up">
                            <span class="id">${item.comName}</span>
                            <span class="time">${item.comTime}</span>
                        </div>
                        <div class="content_in">${item.comContent}</div>
                        <div class="from">
                            <span>${item.comFrom}</span>
                        </div>
                    </div>
                `
                });
                $('.contents').html(ele);
            });
    }, 20)
})(); 